<template>
  <el-select v-model="value" value-key="code" filterable placeholder="请选择" @change="changeValue($event)" clearable style="width:100%">
    <el-option
      v-for="item in inventoryStatusList"
      :key="item.code"
      :label="item.name"
      :value="item"
    />
  </el-select>
</template>

<script>
  import request from '@/utils/request'
  export default {
    data() {
      return {
        value: '',
        inventoryStatusList: [],
        shipmentCode: '',
      }
    },

    created() {
    },
    methods: {
      init(shipmentCode = ''){
        this.shipmentCode = shipmentCode;
        this.value = '';
        this.findInventoryStatus()
      },

      findInventoryStatus() {
        return request({
          url: '/wms/inventoryStatus/chooseData',
          method: 'get',
          params: { shipmentCode: this.shipmentCode }
        }).then(response => {
          this.inventoryStatusList = response.data
          this.changeValue(response.data[0])
          this.value = response.data[0].name
        })
      },

      changeValue(e) {
        this.$emit("setInventoryStatus", e)
      },

      // 设定初始值
      setSelectValue(value) {
        this.findInventoryStatus().then(() => {
          if (value != '') {
            this.inventoryStatusList.forEach(i => {
              if (i.code == value) {
                this.value = i.name
              }
              if (i.name == value) {
                this.value = value
              }
            })
          } else {
            this.value = value
          }
        })
      },
    }
  }
</script>
